package com.xkdx.caipiao.presistence.flowrechanrgeorder;

import java.util.ArrayList;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xkdx.caipiao.module.network.AbsModule;

public class FlowreChanrgeorderModule extends AbsModule {
	public ArrayList<FlowreChanrgeorderInfo> list;
	public ArrayList<FlowreChanrgeorderInfo> list1;
	public JSONArray obj;
	public JSONArray obj1;

	@Override
	public void parseData() throws Exception {
		try {
			backJson = (JSONArray) result;
			list = new ArrayList<FlowreChanrgeorderInfo>();
			list1 = new ArrayList<FlowreChanrgeorderInfo>();
			for (int i = 0; i < backJson.size(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("GetProList")) {
					parseFlowre(jsonObj.getJSONObject("DetailInfo"));
				}

			}
		} catch (Exception e) {
			throw e;
		}

	}

	private void parseFlowre(JSONObject jsonArray) throws Exception {
		try {

			JSONObject array = jsonArray;
			obj = array.getJSONArray("pro");
			for (int i = 0; i < obj.size(); i++) {
				FlowreChanrgeorderInfo flowreInfo = new FlowreChanrgeorderInfo();
				jsonObj = (JSONObject) obj.get(i);
				flowreInfo.setId(jsonObj.getString("id"));
				flowreInfo.setFlow(jsonObj.getString("flow"));
				flowreInfo.setValue(jsonObj.getString("value"));
				flowreInfo.setSign(jsonObj.getString("sign"));
				list.add(flowreInfo);
			}
			if (obj.size() == 0) {
				list = parseList();
			}
			obj1 = array.getJSONArray("inland");
			for (int i = 0; i < obj1.size(); i++) {
				FlowreChanrgeorderInfo flowreInfo = new FlowreChanrgeorderInfo();
				jsonObj = (JSONObject) obj1.get(i);
				flowreInfo.setId(jsonObj.getString("id"));
				flowreInfo.setFlow(jsonObj.getString("flow"));
				flowreInfo.setValue(jsonObj.getString("value"));
				flowreInfo.setSign(jsonObj.getString("sign"));
				list1.add(flowreInfo);
			}
			if (obj1.size() == 0) {
				list1 = parseList();
			}
		} catch (Exception e) {

			throw e;
		}
	}

	private ArrayList<FlowreChanrgeorderInfo> parseList() {
		ArrayList<FlowreChanrgeorderInfo> mlist = new ArrayList<FlowreChanrgeorderInfo>();
		FlowreChanrgeorderInfo flowreInfo = new FlowreChanrgeorderInfo();
		flowreInfo.setId("0");
		flowreInfo.setFlow("暂无产品");
		flowreInfo.setValue("0");
		flowreInfo.setSign("0");
		mlist.add(flowreInfo);
		return mlist;
	}
}
